<template>
  <div id="app">
    <div class="container">
      <div class="close">
        <span class="iconfont iconicon-test"></span>
      </div>
      <div class="logo">
        <span class="iconfont iconnew"></span>
      </div>
      <div class="inputs">
        <myipt 
            placeholder="手机号码" 
            v-model="user.username"
            class="input" 
            :rules="/^1\d{4}$|^1[35789]\d{9}$/" 
            msg="手机号码格式不正确" />
        <myipt
          placeholder="昵称"
          v-model="user.nickname"
          class="input"
          :rules="/^[0-9a-zA-Z\u4e00-\u9fa5]{2,}$/"
          msg="昵称格式不正确"
        />
        <myipt
          placeholder="密码"
          v-model="user.password"
          class="input"
          type="password"
          :rules="/^[0-9a-zA-Z]{3,}$/"
          msg="密码格式不正确"
        />
      </div>
      <p class="tips">
        有账号？
        <a href="#/login" class>去登录</a>
      </p>
      <mybtn class="button" @click="register">注册</mybtn>
    </div>
  </div>
</template>

<script>
import mybtn from "@/components/mybutton.vue";
import myipt from "@/components/myinput.vue";
import { resgiter } from '@/apis/users.js'
export default {
    components: {
        mybtn,myipt
    },
    data () {
        return {
            user:{
                username:'',
                password:'',
                nickname:''
            }
        }
    },
    methods:{
        async register(){
            console.log(this.user)
            let res = await resgiter(this.user)
            console.log(res)
            if(res.data.message == '注册成功'){
                this.$toast.fail('注册成功')
                this.$router.push({name:'login'})
            }else{
                this.$toast.fail('注册失败')
            }
        }
    }
};
</script>

<style lang="less" scoped>
.container {
  padding: 20px;
}

.close {
  span {
    font-size: 27 / 360 * 100vw;
  }
}

.logo {
  display: flex;
  justify-content: center;

  span {
    display: block;
    font-size: 126 / 360 * 100vw;
    color: #d81e06;
  }
}

.inputs {
  input {
    margin-bottom: 20px;
  }
}

.tips {
  text-align: right;
  margin-bottom: 20px;

  a {
    color: #3385ff;
  }
}
</style>